package cn.edu.sdjzu.usercenter.exception;

import cn.edu.sdjzu.usercenter.common.BaseResponse;
import cn.edu.sdjzu.usercenter.common.ErrorCode;
import cn.edu.sdjzu.usercenter.common.ResultUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * @projectName: user-center
 * @package: cn.edu.sdjzu.usercenter.exception
 * @className: GlobalExceptionHandler
 * @author: Liu
 * @description: 全局异常处理器
 * @date: 2024/3/29 16:56
 * @version: 1.0
 */

@RestControllerAdvice
@Slf4j
public class GlobalExceptionHandler {

    @ExceptionHandler(BusinessException.class)
    public BaseResponse businessExceptionHandler(BusinessException e){
        log.error("businessException : " + e.getMessage(),e);
        return ResultUtils.error(e.getCode(),e.getMessage(),e.getDescription());
    }

    @ExceptionHandler(RuntimeException.class)
    public BaseResponse runtimeExceptionHandler(RuntimeException e){
        log.error("runtimeException",e);
        return ResultUtils.error(ErrorCode.SYSTEM_ERROR,e.getMessage(),"");

    }



}
